﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;

namespace PermDoc.DB
{
    public struct Kontragent : IComparer
    {
        #region Members
        public Guid Id { get; set; }
        public string Name { get; set; }
        #endregion
        #region Constructors
        public Kontragent(Kontragent src)
            : this()
        {
            Copy(src);
        }
        public Kontragent(string str)
            : this()
        {
            Copy(str);
        }
        #endregion
        public void Copy(Kontragent src)
        {
            this.Id = src.Id;
            this.Name = src.Name;
        }
        public void Copy(string str)
        {
            if (String.IsNullOrEmpty(str))
                return;
            string[] separator = { "|" };
            string[] s = str.Split(separator, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length < 2)
                return;
            Id = Guid.Parse(s[1]);
            Name = s[0];
        }
        public static implicit operator Kontragent(string s)
        {
            return new Kontragent(s);
        }
        public override bool Equals(System.Object obj)
        {
            if (obj == null)
                return false;
            Kontragent p = (Kontragent)obj;
            if ((System.Object)p == null)
                return false;
            return (this.Id == p.Id);
        }
        public bool Equals(Shop p)
        {
            if ((object)p == null)
                return false;
            return (this.Id == p.Id);
        }
        public static bool operator ==(Kontragent a, Kontragent b)
        {
            if (System.Object.ReferenceEquals(a, b))
                return true;
            if (((object)a == null) || ((object)b == null))
                return false;
            return a.Id == b.Id;
        }
        public static bool operator !=(Kontragent a, Kontragent b)
        {
            return !(a == b);
        }
        public override string ToString()
        {
            return Name;
        }
        public override int GetHashCode()
        {
            return Name.GetHashCode();
        }
        public int Compare(object x, object y)
        {
            return ((Kontragent)x).Id.CompareTo(((Kontragent)y).Id);
        }
    }
}
